import sys
sys.path.append("../")

from frameworks.cores.LoadClass import *

import sys
import os

class TaskController:
    def __init__(self):
        self.loader = LoadClass()

    def run(self):
        #获取队列任务
        queues = self.loader.load("controller.projects.ProjectQueueController","ProjectQueueController",{
            "func":"getAllMapData"
        })
        for queue in queues:
            print(queues)
        exit(0)
        # 执行ls命令列出当前目录下的文件
        os.chdir("../data/app")
        #giturl = "https://gitee.com/funrock/flask-demo.git"
        #result = os.system('dir; && git clone ' + giturl)
        #print("命令执行完毕，返回值为：", result)
        """
        files = os.listdir("./")
        for file in files:
            if os.path.isdir("./"+file):
                print(file + "是目录")
                os.rename("./"+file,"./application")
            else:
                print(file + "不是目录")
        
        with open("../data/app/version","w+") as file:
            file.write("1.0\n")
        """
        with open("./application/Dockfile","w+") as file:
            file.write("FROM python:3.8-slim-buster\n")
            file.write("MAINTAINER fengwei\n")
            file.write("ENV TZ 'Asia/Shanghai'\n")
            file.write("RUN apt-get update && apt-get install -y procps\n")
            file.write("RUN apt-get update && apt-get install -y vim\n")
            file.write("ADD . /root/app\n")
            file.write("ADD requirements.txt requirements.txt\n")
            file.write("RUN pip config set --user global.index-url https://pypi.tuna.tsinghua.edu.cn/simple\n")
            file.write("RUN pip config set --user install.trusted-host https://pypi.tuna.tsinghua.edu.cn\n")
            file.write("RUN pip install --upgrade pip\n")
            file.write("RUN ['pip', 'install', '-r', 'requirements.txt']\n")
            file.write("RUN mkdir -p /root/logs\n")
            file.write("WORKDIR /root/app\n")
            file.write("RUN  chmod +x start.sh\n")
            file.write("ENTRYPOINT ['./start.sh']\n")
            file.write()
        os.chdir("./application/")
        print(os.system("docker build -t app ."))
        #print(os.system("docker push ")